package 多线程.JUC常见类Callable接口;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class Main {
    public static void main(String[] args) throws InterruptedException, ExecutionException {
        Callable<Integer> callable = new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                int result = 0;
                for(int i =1;i<=1000;i++){
                    result+=i;
                }
                return result;
            }
        };

        //接受小票
        FutureTask task = new FutureTask(callable);
        Thread t1 = new Thread(task);

        t1.start();
        t1.join();
        System.out.println(task.get());
    }
}
